Skip to content

feat: support array of minimizers for minify and terserOptions#666

Merged
alexander-akait merged 7 commits intomainfrom
claude/add-ministers-array-support-JNpuI
May 4, 2026
Merged

feat: support array of minimizers for minify and terserOptions#666
alexander-akait merged 7 commits intomainfrom
claude/add-ministers-array-support-JNpuI

Conversation

@alexander-akait
Copy link
Copy Markdown
Member

The minify option now accepts an array of minifier functions that are
executed sequentially, piping the code (and source map) of each step into
the next. terserOptions can correspondingly be an array of option objects
(index-paired with minify) or a single object shared by every minimizer.
Warnings, errors and extracted comments from all minimizers are merged.

Matches the array support already available in html-minimizer-webpack-plugin.

claude added 5 commits April 24, 2026 13:24
The `minify` option now accepts an array of minifier functions that are
executed sequentially, piping the code (and source map) of each step into
the next. `terserOptions` can correspondingly be an array of option objects
(index-paired with `minify`) or a single object shared by every minimizer.
Warnings, errors and extracted comments from all minimizers are merged.

Matches the array support already available in html-minimizer-webpack-plugin.
When a step in the `minify` array does not return a `code` string, keep
the last-known-good code (or original input) and feed it to the next
step, rather than breaking out of the loop. Errors and warnings from
the skipped step are still surfaced. If no step in the chain ever
produces code, the existing "Minimizer doesn't return result" error
still fires.

Matches the behavior in html-minimizer-webpack-plugin.
Moves the previously-private TerserPlugin.getEcmaVersion static method
into src/utils.js (where the minimizer functions live), since the
ecma-version derivation only matters for the minimizers that consume
ecma (terserMinify, swcMinify). The plugin now imports getEcmaVersion
from utils.js. No behavior change.
Some minimizers legitimately return only warnings, errors or extracted
comments without producing new code. The plugin previously pushed a
spurious "Minimizer doesn't return result" error in that case, on top
of any real diagnostics the minimizer emitted.

Now:
* no synthetic error is added when `code` is `undefined`
* warnings and errors from the minimizer are still surfaced
* the LICENSE file is still emitted when `extractedComments` are
  returned without code; the banner is only prepended when a new
  source replaces the asset
* the main asset is left unchanged when no minimizer in the chain
  produces code
Map more of webpack's `output.environment` flags to ECMAScript versions
and pick the highest matching version when several flags are set:

* ES2015 now also includes `methodShorthand` and `templateLiteral`
* ES2017 added — triggered by `asyncFunction`
* ES2020 now also includes `dynamicImportInWorker`, `globalThis`
  and `optionalChaining`

Previously the function checked ES2015 before ES2020, so an environment
that supported both (e.g. webpack production defaults) was downgraded to
ES2015 — which left ES2017–ES2020 minification opportunities on the
table. Now the highest version wins.

Effect: when webpack signals modern features, swcMinify can now drop
the unused `catch (e)` binding (ES2019 optional catch binding), which
shows up in the updated snapshots.
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 30, 2026

CLA Not Signed

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 99.06542% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.36%. Comparing base (d569842) to head (aea418c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/minify.js 96.55% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #666      +/-   ##
==========================================
+ Coverage   96.76%   97.36%   +0.60%     
==========================================
  Files           3        3              
  Lines         340      380      +40     
  Branches      125      152      +27     
==========================================
+ Hits          329      370      +41     
+ Misses         11       10       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexander-akait alexander-akait merged commit e62c2f8 into main May 4, 2026
28 of 29 checks passed
@alexander-akait alexander-akait deleted the claude/add-ministers-array-support-JNpuI branch May 4, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants